/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : led.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2021-01-15 init v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
********************************************************************************
*/
#include <stdio.h>
#include "led.h"

#define LED_LOGD(fmt, args...)
#define LED_LOGI(fmt, args...) printf("%d Led I: " fmt, __LINE__, ##args)
#define LED_LOGW(fmt, args...) printf("%d Led W: " fmt, __LINE__, ##args)
#define LED_LOGE(fmt, args...) printf("%d Led E: " fmt, __LINE__, ##args)
#define LED_LOG(fmt, args...)  printf(fmt, ##args)


static const char LED_MODE_STR[][20] = {"Default Mode", "Horse Mode", "Breath Mode"};
static const char LENGTH_LED_NAME = 10;
static const char SHARED_LED_PIN[MAX_SHARED_LED][LENGTH_LED_NAME] = {"pin20", "pin21"};
static const char UNSHARED_LED_PIN[LENGTH_LED_NAME] = "pin10";

void CLed::SetStatus(ELedStatus status)
{
    mStatus = status;
}

ELedStatus CLed::GetStatus()
{
    return mStatus;
}

// 资源释放时，所有状态复位. Stop Led
void CLed::Relase()
{
    mStatus = LED_IDLE;
    Stop();    // 释放时，保证Led处于未使用状态
    LED_LOG("Relase Led %d (%s)\n", mIndex, SHARED_LED_PIN[mIndex]);
}

void CLed::SetUsedMode(EUsedMode mode)
{
    mUsedMode = mode;
}

EUsedMode CLed::GetUsedMode()
{
    return mUsedMode;
}

void CLed::SetPermission(EPermission permission)
{
    mPermission = permission;
}

EPermission CLed::GetPermission()
{
    return mPermission;
}

void CLed::SetFrequency(int freq)
{
    mFreq = freq;
}

void CLed::SetIndex(int value)
{
    mIndex = value;
}

void CLed::UpdateLed(EPermission permission, EUsedMode mode, int freq)
{
    SetPermission(permission);
    SetUsedMode(mode);
    SetFrequency(freq);
}

void CLed::Start()
{
    LED_LOG("Led %d (%s) Start. Mode: %s \n", mIndex, SHARED_LED_PIN[mIndex], LED_MODE_STR[mUsedMode]);
}

void CLed::Stop()
{
    LED_LOG("Led %d (%s) Stop\n", mIndex, SHARED_LED_PIN[mIndex]);
}

// ---------------- CUnsharedLed ----------------
void CUnsharedLed::Start()
{
    LED_LOG("Power Led (%s) ON. \n", UNSHARED_LED_PIN);
}

void CUnsharedLed::Stop()
{
    LED_LOG("Power Led (%s) OFF.\n", UNSHARED_LED_PIN);
}

void CUnsharedLed::Relase()
{
    SetStatus(LED_IDLE);
    Stop();
    LED_LOG("Relase power Led (%s).\n", UNSHARED_LED_PIN);
}

